<?php
/**
* Class GenerateManageAdmin into Bo Controller
* @author SillySmart
* @copyright SillySmart
* @package Mvc.Controllers.Bo
* @see Mvc.Controllers.Bo.ControllerProtected
* @see Mvc.Controllers.SiteProtected
* @see Sls.Controllers.Core.SLS_GenericController
* @since 1.0
*
*/
class SLS_BoGenerateManageAdmin extends SLS_BoControllerProtected
{
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$controllersXML = $this->_generic->getControllersXML();
		$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));		
		$action = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='ManageAdmin']"));		
		/*
		// Check if bo controller already exist
		if (empty($controller))
		{
			$xml->startTag("errors");
			$xml->addFullTag("error","Back-office controller could not be found. Please follow the following link to create it",true);
			$xml->endTag("errors");
			$xml->addFullTag("error_type","rights",true);
		}
		// If action already exist
		else if (!empty($action))
		{
			$xml->startTag("errors");
			$xml->addFullTag("error","ManageAdmin action already exists",true);
			$xml->endTag("errors");			
		}
		// Else, let's generate action
		else 
		{
			$langs = $this->_generic->getObjectLang()->getSiteLangs();
			
			// ManageAdmin
			$params = array(0 => array("key" 	=> "reload",
					  				   "value" 	=> "true"),
					  		1 => array("key" 	=> "Controller",
					  				   "value" 	=> $controller),
						 	2 => array("key" 	=> "actionName",
					  				   "value" 	=> "ManageAdmin"),
					  		3 => array("key"	=> "token",
					  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
					  		4 => array("key"	=> "indexes",
					  				   "value"	=> "noindex,nofollow")					  			
						    );
			foreach($langs as $lang)
			{
				$tmpParam = array("key" 	=> $lang."-action",
								  "value" 	=> "ManageAdmin");
				$tmpTitle = array("key" 	=> $lang."-title",
								  "value" 	=> "ManageAdmin");
				array_push($params,$tmpParam);
				array_push($params,$tmpTitle);
			}
			file_get_contents($this->_generic->getFullPath("SLS_Bo",
														  "AddAction",
														  $params,
														  true));
			$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdmin".".controller.php");
			
			
			$action = 	t(2).'$xml = $this->getXML();'."\n".
				        t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
				        t(2).'$xml->startTag("bo_actions");'."\n".
				        t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
				        t(2).'{'."\n".
				        '            $xml->startTag("bo_action");'."\n".
				        '            foreach($boActions[$i] as $key => $value)'."\n".
				        '                $xml->addFullTag($key,$value,true);'."\n".
				        '            $xml->endTag("bo_action");'."\n".
				        t(2).'}'."\n".
				        t(2).'$xml->endTag("bo_actions");'."\n\n".        
				        t(2).'// Check account rights'."\n".
				        t(2).'$right = SLS_BoRights::getRight();'."\n".        
				        t(2).'if ($right != "GOD")'."\n".
				        	t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
				        t(2).'// /Check account rights'."\n\n".                
						t(2).'$xmlRights = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"));'."\n".		
						t(2).'$admins = $xmlRights->getTagsAttributes("//sls_configs/entry",array("login","right"));'."\n".
						t(2).'$xml->startTag("admins");'."\n".
						t(2).'for($i=0 ; $i<$count=count($admins) ; $i++)'."\n".
						t(2).'{'."\n".
							t(3).'$right = $admins[$i]["attributes"][1]["value"];'."\n".
							t(3).'$rightLitteral = \'View\';'."\n".
							t(3).'$privilege = "Simple Admin";'."\n\n".			
							t(3).'if ($right == "GOD")'."\n".
							t(3).'{'."\n".
								t(4).'$right = "AMD";'."\n".
								t(4).'$privilege = "Super Admin";'."\n".	
							t(3).'}'."\n\n".			
							t(3).'for($j=0 ; $j<strlen($right) ; $j++)'."\n".
							t(3).'{'."\n".
								t(4).'switch ($right{$j})'."\n".
								t(4).'{'."\n".
									t(5).'case \'A\': $rightLitteral .= \', Add\'; 	break;'."\n".
									t(5).'case \'M\': $rightLitteral .= \', Modify\'; break;'."\n".
									t(5).'case \'D\': $rightLitteral .= \', Delete\'; break;'."\n".
								t(4).'}'."\n".
							t(3).'}'."\n\n".			
							t(3).'$xml->startTag("admin");'."\n".
							t(3).'$xml->addFullTag("login",$admins[$i]["attributes"][0]["value"],true);'."\n".
							t(3).'$xml->addFullTag("right",$rightLitteral,true);'."\n".
							t(3).'$xml->addFullTag("privilege",$privilege,true);'."\n".
							t(3).'$xml->endTag("admin");'."\n".
						t(2).'}'."\n".
						t(2).'$xml->endTag("admins");'."\n\n".		
						t(2).'$xml->addFullTag("url_add",$this->_generic->getFullPath("'.$controller.'","ManageAdminAdd"),true);'."\n".
						t(2).'$xml->addFullTag("url_edit",$this->_generic->getFullPath("'.$controller.'","ManageAdminModify",array(),false),true);'."\n".
						t(2).'$xml->addFullTag("url_delete",$this->_generic->getFullPath("'.$controller.'","ManageAdminDelete",array(),false),true);'."\n\n".		
				        t(2).'$this->saveXML($xml);'."\n";
				      
			$source = substr($source,0,strpos($source,"action()")+8)."\n".
							  t(1).'{'."\n".
							  $action.
							  t(1).'}'."\n".
							  '}'."\n".
							  '?>';
			file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdmin.controller.php",$source);
						
			$sourceXsl = 	'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
							'<xsl:template name="ManageAdmin">'."\n".
							t(2).'<xsl:call-template name="BoMenu" />'."\n".
							t(2).'<script type="text/javascript">'."\n".
								t(3).'var sls_confirm_msg = \'<xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_list_delete_confirm\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>\';'."\n".
							t(2).'</script>'."\n".
							t(2).'<script type="text/javascript">'."\n".
								t(3).'var page = \'listing\';'."\n".
								t(3).'var modify = \'<xsl:value-of select="concat(//View/url_edit,\'/id/\')" />\';'."\n".
								t(3).'var del = \'<xsl:value-of select="concat(//View/url_delete,\'/id/\')" />\';'."\n".
							t(2).'</script>'."\n".
							t(2).'<h1 class="main">Results for : <span class="light">admins - <xsl:value-of select="count(//View/admins/admin)" />&#160;result<xsl:if test="count(//View/admins/admin) &gt; 1">s</xsl:if></span></h1>'."\n".
							t(2).'<ul class="listing_actions">'."\n".
								t(3).'<li><a href="{//View/url_add}" title="" class="add"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_list_add\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></a></li>'."\n".			
								t(3).'<li><span class="edit"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_list_edit\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></span></li>'."\n".
								t(3).'<li><span class="delete"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_list_delete\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></span></li>'."\n".
							t(2).'</ul>'."\n\n".									
							t(2).'<xsl:if test="count(//View/admins/admin) = 0">'."\n".
								t(3).'<ul class="error" style="display:block;float:left;margin-top:20px;">'."\n".
									t(4).'<li><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_list_results_nothing\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></li>'."\n".
								t(3).'</ul>'."\n".
							t(2).'</xsl:if>'."\n\n".									
							t(2).'<xsl:if test="count(//View/admins/admin) &gt; 0">'."\n".	
								t(3).'<table class="listing" cellpadding="0" cellspacing="0">'."\n".
									t(4).'<tr>'."\n".
										t(5).'<th>&#160;</th>'."\n".					
										t(5).'<th valign="middle">Login</th>'."\n".
										t(5).'<th valign="middle">Right</th>'."\n".
										t(5).'<th valign="middle">Privilege</th>'."\n".
									t(4).'</tr>'."\n".
									t(4).'<xsl:for-each select="//View/admins/admin">'."\n".
										t(5).'<xsl:variable name="currentPosition" select="position()" />'."\n".
										t(5).'<xsl:variable name="trClass">'."\n".
											t(6).'<xsl:if test="position() mod 2  = 0">dark</xsl:if>'."\n".
											t(6).'<xsl:if test="position() mod 2 != 0">clear</xsl:if>'."\n".
										t(5).'</xsl:variable>'."\n".
										t(5).'<tr class="{$trClass}">'."\n".
											t(6).'<td class="check"><input type="checkbox" id="{login}" class="filter_checkbox" /></td>'."\n".
											t(6).'<td><xsl:value-of select="login" /></td>'."\n".
											t(6).'<td><xsl:value-of select="right" /></td>'."\n".
											t(6).'<td><xsl:value-of select="privilege" /></td>'."\n".
										t(5).'</tr>'."\n".
									t(4).'</xsl:for-each>'."\n".
								t(3).'</table>'."\n".
							t(2).'</xsl:if>'."\n".
							'</xsl:template>'."\n".
							'</xsl:stylesheet>';
			file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/ManageAdmin.xsl",$sourceXsl);
			// ManageAdmin
			
			// ManageAdminAdd
			$params = array(0 => array("key" 	=> "reload",
					  				   "value" 	=> "true"),
					  		1 => array("key" 	=> "Controller",
					  				   "value" 	=> $controller),
						 	2 => array("key" 	=> "actionName",
					  				   "value" 	=> "ManageAdminAdd"),
					  		3 => array("key"	=> "token",
					  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
					  		4 => array("key"	=> "indexes",
					  				   "value"	=> "noindex,nofollow")					  			
						    );
			foreach($langs as $lang)
			{
				$tmpParam = array("key" 	=> $lang."-action",
								  "value" 	=> "ManageAdminAdd");
				$tmpTitle = array("key" 	=> $lang."-title",
								  "value" 	=> "ManageAdminAdd");
				array_push($params,$tmpParam);
				array_push($params,$tmpTitle);
			}
			file_get_contents($this->_generic->getFullPath("SLS_Bo",
														  "AddAction",
														  $params,
														  true));
			$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminAdd".".controller.php");
			
			
			$action = 	t(2).'$xml = $this->getXML();'."\n".
				        t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
				        t(2).'$xml->startTag("bo_actions");'."\n".
				        t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
				        t(2).'{'."\n".
					        t(3).'$xml->startTag("bo_action");'."\n".
					        t(3).'foreach($boActions[$i] as $key => $value)'."\n".
					        	t(4).'$xml->addFullTag($key,$value,true);'."\n".
					        t(3).'$xml->endTag("bo_action");'."\n".
				        t(2).'}'."\n".
				        t(2).'$xml->endTag("bo_actions");'."\n\n".        
				        t(2).'// Check account rights'."\n".
				        t(2).'$right = SLS_BoRights::getRight();'."\n".        
				        t(2).'if ($right != "GOD")'."\n".
				        	t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
				        t(2).'// /Check account rights'."\n\n".                
						t(2).'if ($this->_http->getParam("reload_add") == "true")'."\n".
				        t(2).'{'."\n".
					        t(3).'$errors = array();'."\n\n".				        	
					        t(3).'$login = SLS_String::trimSlashesFromString($this->_http->getParam("admin_login"));'."\n".
							t(3).'$pwd 	= SLS_String::trimSlashesFromString($this->_http->getParam("admin_password"));'."\n".
							t(3).'$privilege = SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege"));'."\n".
							t(3).'$add = SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_add"));'."\n".
							t(3).'$modify = SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_modify"));'."\n".
							t(3).'$delete = SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_delete"));'."\n\n".							
					       	t(3).'$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");'."\n".
							t(3).'$xmlRights = new SLS_XMLToolbox($pathsHandle);'."\n".
							t(3).'$result = $xmlRights->getTags("//sls_configs/entry[@login=\'".($login)."\']");'."\n\n".							
							t(3).'if (!empty($result))'."\n".
							t(3).'{'."\n".
								t(4).'$xml->startTag("errors");'."\n".
								t(4).'$xml->addFullTag("error","This account already exists",true);'."\n".
								t(4).'$xml->endTag("errors");'."\n".
							t(3).'}'."\n".
							t(3).'else'."\n".
							t(3).'{'."\n".
								t(4).'$right = "R";'."\n\n".								
								t(4).'if (empty($login) || empty($pwd))'."\n".
								t(4).'{'."\n".
									t(5).'$xml->startTag("errors");'."\n".
									t(5).'$xml->addFullTag("error","You must fill the login and the password",true);'."\n".
									t(5).'$xml->endTag("errors");'."\n".
									t(5).'$xml->startTag("admin");'."\n".
									t(5).'$xml->addFullTag("login",$login,true);'."\n".
									t(5).'$xml->addFullTag("privilege_add",(!empty($add)) ? "true" : "false",true);'."\n".
									t(5).'$xml->addFullTag("privilege_modify",(!empty($modify)) ? "true" : "false",true);'."\n".
									t(5).'$xml->addFullTag("privilege_delete",(!empty($delete)) ? "true" : "false",true);'."\n".
									t(5).'$xml->endTag("admin");'."\n".
								t(4).'}'."\n".
								t(4).'else'."\n".
								t(4).'{'."\n".
									t(5).'if (!empty($add))'."\n".
										t(6).'$right .= "A";'."\n".
									t(5).'if (!empty($modify))'."\n".
										t(6).'$right .= "M";'."\n".
									t(5).'if (!empty($delete))'."\n".
										t(6).'$right .= "D";'."\n\n".										
									t(5).'if ($privilege == "god")'."\n".
										t(6).'$right = "GOD";'."\n\n".										
									t(5).'$xmlNew = \'<entry login="\'.($login).\'" password="\'.sha1($pwd).\'" right="\'.$right.\'" />\';'."\n".
									t(5).'$xmlRights->appendXMLNode("//sls_configs",$xmlNew);'."\n".
									t(5).'$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());'."\n".
									t(5).'$this->_generic->forward("'.$controller.'","ManageAdmin");'."\n".
								t(4).'}'."\n".
							t(3).'}'."\n".
				        t(2).'}'."\n\n".		
				        t(2).'$this->saveXML($xml);'."\n";
				      
			$source = substr($source,0,strpos($source,"action()")+8)."\n".
							  '    {'."\n".
							  $action.
							  '    }'."\n".
							  '}'."\n".
							  '?>';
			file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminAdd.controller.php",$source);
						
			$sourceXsl = 	'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
							'<xsl:template name="ManageAdminAdd">'."\n".
							t(1).'<xsl:call-template name="BoMenu" />'."\n".
							t(1).'<script type="text/javascript">'."\n".
								t(2).'function checkPrivilege()'."\n".
								t(2).'{'."\n".
									t(3).'if (document.getElementById(\'admin_privilege\').value == \'admin\')'."\n".
									t(3).'{'."\n".
										t(4).'checked = false;'."\n".
										t(4).'disabled = false;'."\n".
									t(3).'}'."\n".
									t(3).'else'."\n".
									t(3).'{'."\n".
										t(4).'checked = true;'."\n".
										t(4).'disabled = true;'."\n".
									t(3).'}'."\n".
									t(3).'document.getElementById(\'admin_privilege_add\').checked = checked;'."\n".
									t(3).'document.getElementById(\'admin_privilege_modify\').checked = checked;'."\n".
									t(3).'document.getElementById(\'admin_privilege_delete\').checked = checked;'."\n".
									t(3).'document.getElementById(\'admin_privilege_add\').disabled = disabled;'."\n".
									t(3).'document.getElementById(\'admin_privilege_modify\').disabled = disabled;'."\n".
									t(3).'document.getElementById(\'admin_privilege_delete\').disabled = disabled;'."\n".
								t(2).'}'."\n".
							t(1).'</script>'."\n".
							t(1).'<h1 class="main"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_add_title\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>&#160;<span class="light">Admin</span></h1>'."\n".		
							t(1).'<form action="" method="post" enctype="multipart/form-data">'."\n".
								t(2).'<input type="hidden" name="reload_add" value="true" />'."\n".
								t(2).'<div class="grey_wrapper_no_padding">'."\n".
									t(3).'<ul class="langs">'."\n".
									t(3).'</ul>'."\n".
									t(3).'<div class="edit_form">'."\n".					
										t(4).'<div class="langs_form_wrapper" id="{concat(\'en\', \'_form_wrapper\')}">'."\n".
											t(5).'<xsl:if test="count(//View/errors/error) &gt; 0">'."\n".
												t(6).'<ul class="error">'."\n".
													t(7).'<xsl:for-each select="//View/errors/error">'."\n".									
														t(8).'<li><xsl:value-of select="." /></li>'."\n".
													t(7).'</xsl:for-each>'."\n".
												t(6).'</ul>'."\n".
											t(5).'</xsl:if>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label></label>'."\n".
												t(6).'<span class="warn"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_fields\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_login">Login *</label>'."\n".
												t(6).'<input type="text" value="{//View/admin/login}" name="admin_login" id="admin_login" class="text" />'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_password">Password *</label>'."\n".
												t(6).'<input type="password" value="{//View/admin/password}" name="admin_password" id="admin_password" class="text" />'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_privilege">Privilege *</label>'."\n".
												t(6).'<select name="admin_privilege" id="admin_privilege" onchange="javascript:checkPrivilege()">'."\n".
													t(7).'<option value="admin">'."\n".
														t(8).'<xsl:if test="//View/admin/privilege = \'admin\'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>'."\n".
														t(8).'Simple Admin'."\n".
													t(7).'</option>'."\n".
													t(7).'<option value="god">'."\n".
														t(8).'<xsl:if test="//View/admin/privilege = \'god\'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>'."\n".
														t(8).'Super Admin'."\n".
													t(7).'</option>'."\n".
												t(6).'</select>'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row_radio">'."\n".
												t(6).'<label for="admin_privilege_add">Right *</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_add" id="admin_privilege_add" value="add">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_add = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_add" class="auto">Add</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_modify" id="admin_privilege_modify" value="modify">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_modify = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_modify" class="auto">Modify</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_delete" id="admin_privilege_delete" value="delete">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_delete = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_delete" class="auto">Delete</label>'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n\n".										
										t(4).'</div>'."\n".
									t(3).'</div>'."\n".
								t(2).'</div>'."\n".
								t(2).'<div class="form_validator">'."\n".
									t(3).'<div class="login_submit">'."\n".
										t(4).'<div class="left"></div>'."\n".
										t(4).'<div class="middle">'."\n".
											t(5).'<input type="submit">'."\n".
												t(6).'<xsl:attribute name="value"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_submit\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></xsl:attribute>'."\n".
											t(5).'</input>'."\n".
										t(4).'</div>'."\n".
										t(4).'<div class="right"></div>'."\n".
									t(3).'</div>'."\n".
								t(2).'</div>'."\n".
							t(1).'</form>'."\n".
							'</xsl:template>'."\n".
							'</xsl:stylesheet>';
			file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/ManageAdminAdd.xsl",$sourceXsl);
			// ManageAdminAdd
			
			// ManageAdminModify
			$params = array(0 => array("key" 	=> "reload",
					  				   "value" 	=> "true"),
					  		1 => array("key" 	=> "Controller",
					  				   "value" 	=> $controller),
						 	2 => array("key" 	=> "actionName",
					  				   "value" 	=> "ManageAdminModify"),
					  		3 => array("key"	=> "token",
					  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
					  		4 => array("key"	=> "indexes",
					  				   "value"	=> "noindex,nofollow")					  			
						    );
			foreach($langs as $lang)
			{
				$tmpParam = array("key" 	=> $lang."-action",
								  "value" 	=> "ManageAdminModify");
				$tmpTitle = array("key" 	=> $lang."-title",
								  "value" 	=> "ManageAdminModify");
				array_push($params,$tmpParam);
				array_push($params,$tmpTitle);
			}
			file_get_contents($this->_generic->getFullPath("SLS_Bo",
														  "AddAction",
														  $params,
														  true));
			$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminModify".".controller.php");
			
			
			$action = 	t(2).'$xml = $this->getXML();'."\n".
				        t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
				        t(2).'$xml->startTag("bo_actions");'."\n".
				        t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
				        t(2).'{'."\n".
					        t(3).'$xml->startTag("bo_action");'."\n".
					        t(3).'foreach($boActions[$i] as $key => $value)'."\n".
					        	t(4).'$xml->addFullTag($key,$value,true);'."\n".
					        t(3).'$xml->endTag("bo_action");'."\n".
				        t(2).'}'."\n".
				        t(2).'$xml->endTag("bo_actions");'."\n\n".        
				        t(2).'// Check account rights'."\n".
				        t(2).'$right = SLS_BoRights::getRight();'."\n".        
				        t(2).'if ($right != "GOD")'."\n".
				        	t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
				        t(2).'// /Check account rights'."\n\n".                
						t(2).'$name = SLS_String::trimSlashesFromString($this->_http->getParam("id"));'."\n".
						t(2).'$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");'."\n".
						t(2).'$xmlRights = new SLS_XMLToolbox($pathsHandle);'."\n".
						t(2).'$result = $xmlRights->getTags("//sls_configs/entry[@login=\'".($name)."\']");'."\n\n".						
						t(2).'if (empty($result))'."\n".
						t(2).'{'."\n".
							t(3).'$xml->startTag("errors");'."\n".
							t(3).'$xml->addFullTag("error","This account doesn\'t exists",true);'."\n".
							t(3).'$xml->endTag("errors");'."\n".
						t(2).'}'."\n".
						t(2).'else'."\n".
						t(2).'{'."\n".
							t(3).'$login = $name;'."\n".
							t(3).'$pwd = "";'."\n".
							t(3).'$right = array_shift($xmlRights->getTagsAttribute("//sls_configs/entry[@login=\'".($name)."\']","right"));'."\n".
							t(3).'$right = $right["attribute"];'."\n".
							t(3).'$add = "";'."\n".
							t(3).'$modify = "";'."\n".
							t(3).'$delete = "";'."\n".
							t(3).'for($i=0 ; $i<$count=strlen($right) ; $i++)'."\n".
							t(3).'{'."\n".
								t(4).'if ($right{$i} == "A")'."\n".
									t(5).'$add = "true";'."\n".
								t(4).'if ($right{$i} == "M")'."\n".
									t(5).'$modify = "true";'."\n".
								t(4).'if ($right{$i} == "D")'."\n".
									t(5).'$delete = "true";'."\n".
							t(3).'}'."\n\n".										
							t(3).'if ($this->_http->getParam("reload_edit") == "true")'."\n".
							t(3).'{'."\n".
								t(4).'$errors = array();'."\n\n".								
								t(4).'$login 		= SLS_String::trimSlashesFromString($this->_http->getParam("admin_login"));'."\n".
								t(4).'$pwd 		= SLS_String::trimSlashesFromString($this->_http->getParam("admin_password"));'."\n".
								t(4).'$privilege 	= SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege"));'."\n".
								t(4).'$add 		= SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_add"));'."\n".
								t(4).'$modify 	= SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_modify"));'."\n".
								t(4).'$delete 	= SLS_String::trimSlashesFromString($this->_http->getParam("admin_privilege_delete"));'."\n\n".												
								t(4).'if ($login != $name)'."\n".
								t(4).'{'."\n".
									t(5).'$result = $xmlRights->getTags("//sls_configs/entry[@login=\'".($login)."\']");'."\n".			
									t(5).'if (!empty($result))'."\n".
									t(5).'{'."\n".
										t(6).'array_push($errors,"This account already exists",true);'."\n".
									t(5).'}'."\n".
								t(4).'}'."\n".
								t(4).'if (empty($login) || empty($pwd))'."\n".
								t(4).'{'."\n".
									t(5).'array_push($errors,"You must fill the login and the password");'."\n".					
								t(4).'}'."\n\n".								
								t(4).'if (empty($errors))'."\n".
								t(4).'{'."\n".
									t(5).'$right = "R";'."\n".
									t(5).'if (!empty($add))'."\n".
										t(6).'$right .= "A";'."\n".
									t(5).'if (!empty($modify))'."\n".
										t(6).'$right .= "M";'."\n".
									t(5).'if (!empty($delete))'."\n".
										t(6).'$right .= "D";'."\n\n".										
									t(5).'if ($privilege == "god")'."\n".
										t(6).'$right = "GOD";'."\n\n".
									t(5).'$xmlRights->deleteTags(\'//sls_configs/entry[@login="\'.($login).\'"]\');'."\n".
									t(5).'$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());'."\n".
									t(5).'$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");'."\n".
									t(5).'$xmlRights = new SLS_XMLToolbox($pathsHandle);'."\n".
									t(5).'$xmlNew = \'<entry login="\'.($login).\'" password="\'.sha1($pwd).\'" right="\'.$right.\'" />\';'."\n".
									t(5).'$xmlRights->appendXMLNode("//sls_configs",$xmlNew);'."\n".
									t(5).'$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());'."\n".
									t(5).'$this->_generic->forward("'.$controller.'","ManageAdmin");'."\n".
								t(4).'}'."\n".
								t(4).'else'."\n".
								t(4).'{'."\n".
									t(5).'$xml->startTag("errors");'."\n".
									t(5).'foreach($errors as $error)'."\n".
										t(6).'$xml->addFullTag("error",$error,true);'."\n".
									t(5).'$xml->endTag("errors");'."\n".
								t(4).'}'."\n".
							t(3).'}'."\n".
							t(3).'$xml->startTag("admin");'."\n".
							t(3).'$xml->addFullTag("login",$login,true);'."\n".
							t(3).'$xml->addFullTag("privilege_add",(!empty($add)) ? "true" : "false",true);'."\n".
							t(3).'$xml->addFullTag("privilege_modify",(!empty($modify)) ? "true" : "false",true);'."\n".
							t(3).'$xml->addFullTag("privilege_delete",(!empty($delete)) ? "true" : "false",true);'."\n".
							t(3).'$xml->addFullTag("privilege",($right=="GOD") ? "god" : "admin",true);'."\n".
							t(3).'$xml->endTag("admin");'."\n".
						t(2).'}'."\n\n".		
				        t(2).'$this->saveXML($xml);'."\n";
				      
			$source = substr($source,0,strpos($source,"action()")+8)."\n".
							  t(1).'{'."\n".
							  $action.
							  t(1).'}'."\n".
							  '}'."\n".
							  '?>';
			file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminModify.controller.php",$source);
						
			$sourceXsl = 	'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
							'<xsl:template name="ManageAdminModify">'."\n".
							t(1).'<xsl:call-template name="BoMenu" />'."\n".
							t(1).'<script type="text/javascript">'."\n".
							t(1).'function checkPrivilege()'."\n".
							t(1).'{'."\n".
								t(2).'if (document.getElementById(\'admin_privilege\').value == \'admin\')'."\n".
								t(2).'{'."\n".
									t(3).'checked = false;'."\n".
									t(3).'disabled = false;'."\n".
								t(2).'}'."\n".
								t(2).'else'."\n".
								t(2).'{'."\n".
									t(3).'checked = true;'."\n".
									t(3).'disabled = true;'."\n".
								t(2).'}'."\n".
								t(2).'document.getElementById(\'admin_privilege_add\').checked = checked;'."\n".
								t(2).'document.getElementById(\'admin_privilege_modify\').checked = checked;'."\n".
								t(2).'document.getElementById(\'admin_privilege_delete\').checked = checked;'."\n".
								t(2).'document.getElementById(\'admin_privilege_add\').disabled = disabled;'."\n".
								t(2).'document.getElementById(\'admin_privilege_modify\').disabled = disabled;'."\n".
								t(2).'document.getElementById(\'admin_privilege_delete\').disabled = disabled;'."\n".
							t(2).'}'."\n".
							t(1).'</script>'."\n".
							t(1).'<h1 class="main"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_add_title\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>&#160;<span class="light">Admin</span></h1>'."\n".		
							t(1).'<form action="" method="post" enctype="multipart/form-data">'."\n".
								t(2).'<input type="hidden" name="reload_edit" value="true" />'."\n".
								t(2).'<div class="grey_wrapper_no_padding">'."\n".
									t(3).'<ul class="langs">'."\n".
									t(3).'</ul>'."\n".
									t(3).'<div class="edit_form">'."\n".					
										t(4).'<div class="langs_form_wrapper" id="{concat(\'en\', \'_form_wrapper\')}">'."\n".
											t(5).'<xsl:if test="count(//View/errors/error) &gt; 0">'."\n".
												t(6).'<ul class="error">'."\n".
													t(7).'<xsl:for-each select="//View/errors/error">'."\n".									
														t(8).'<li><xsl:value-of select="." /></li>'."\n".
													t(7).'</xsl:for-each>'."\n".
												t(6).'</ul>'."\n".
											t(5).'</xsl:if>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label></label>'."\n".
												t(6).'<span class="warn"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_fields\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_login">Login *</label>'."\n".
												t(6).'<input type="text" value="{//View/admin/login}" name="admin_login" id="admin_login" class="text" />'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_password">Password *</label>'."\n".
												t(6).'<input type="password" value="{//View/admin/password}" name="admin_password" id="admin_password" class="text" />'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row">'."\n".
												t(6).'<label for="admin_privilege">Privilege *</label>'."\n".
												t(6).'<select name="admin_privilege" id="admin_privilege" onchange="javascript:checkPrivilege()">'."\n".
													t(7).'<option value="admin">'."\n".
														t(8).'<xsl:if test="//View/admin/privilege = \'admin\'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>'."\n".
														t(8).'Simple Admin'."\n".
													t(7).'</option>'."\n".
													t(7).'<option value="god">'."\n".
														t(8).'<xsl:if test="//View/admin/privilege = \'god\'"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>'."\n".
														t(8).'Super Admin'."\n".
													t(7).'</option>'."\n".
												t(6).'</select>'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n".
											t(5).'<div class="row_radio">'."\n".
												t(6).'<label for="admin_privilege_add">Right *</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_add" id="admin_privilege_add" value="add">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_add = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_add" class="auto">Add</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_modify" id="admin_privilege_modify" value="modify">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_modify = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_modify" class="auto">Modify</label>'."\n".
												t(6).'<input class="radio" type="checkbox" name="admin_privilege_delete" id="admin_privilege_delete" value="delete">'."\n".
													t(7).'<xsl:if test="//View/admin/privilege_delete = \'true\'"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if>'."\n".
												t(6).'</input>'."\n".
												t(6).'<label for="admin_privilege_delete" class="auto">Delete</label>'."\n".
												t(6).'<span class="icon"></span>'."\n".
											t(5).'</div>'."\n\n".										
										t(4).'</div>'."\n".									
									t(3).'</div>'."\n".
								t(2).'</div>'."\n".
								t(2).'<div class="form_validator">'."\n".
									t(3).'<div class="login_submit">'."\n".
										t(4).'<div class="left"></div>'."\n".
										t(4).'<div class="middle">'."\n".
											t(5).'<input type="submit">'."\n".
												t(6).'<xsl:attribute name="value"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_submit\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></xsl:attribute>'."\n".
											t(5).'</input>'."\n".
										t(4).'</div>'."\n".
										t(4).'<div class="right"></div>'."\n".
									t(3).'</div>'."\n".
								t(2).'</div>'."\n".
							t(1).'</form>'."\n".
							'</xsl:template>'."\n".
							'</xsl:stylesheet>';
			file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/ManageAdminModify.xsl",$sourceXsl);
			// ManageAdminModify
			
			// ManageAdminDelete
			$params = array(0 => array("key" 	=> "reload",
					  				   "value" 	=> "true"),
					  		1 => array("key" 	=> "Controller",
					  				   "value" 	=> $controller),
						 	2 => array("key" 	=> "actionName",
					  				   "value" 	=> "ManageAdminDelete"),
					  		3 => array("key"	=> "token",
					  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
					  		4 => array("key"	=> "indexes",
					  				   "value"	=> "noindex,nofollow")					  			
						    );
			foreach($langs as $lang)
			{
				$tmpParam = array("key" 	=> $lang."-action",
								  "value" 	=> "ManageAdminDelete");
				$tmpTitle = array("key" 	=> $lang."-title",
								  "value" 	=> "ManageAdminDelete");
				array_push($params,$tmpParam);
				array_push($params,$tmpTitle);
			}
			file_get_contents($this->_generic->getFullPath("SLS_Bo",
														  "AddAction",
														  $params,
														  true));
			$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminDelete".".controller.php");
			
			
			$action = 	t(2).'// Check account rights'."\n".
				        t(2).'$right = SLS_BoRights::getRight();'."\n".        
				        t(2).'if ($right != "GOD")'."\n".
				        	t(3).'$this->_generic->redirect("Bo/Connection.sls");'."\n".
				        t(2).'// /Check account rights'."\n\n".				        
				        t(2).'$names = SLS_String::trimSlashesFromString($this->_http->getParam("id"));'."\n".
				       	t(2).'$namesE = explode("|",$names);'."\n".
						t(2).'$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");'."\n".
						t(2).'$xmlRights = new SLS_XMLToolbox($pathsHandle);'."\n\n".				
						t(2).'foreach($namesE as $name)'."\n".
						t(2).'{'."\n".
							t(3).'$result = $xmlRights->getTags("//sls_configs/entry[@login=\'".($name)."\']");'."\n\n".							
							t(3).'if (!empty($result))'."\n".
							t(3).'{'."\n".
								t(4).'$xmlRights->deleteTags(\'//sls_configs/entry[@login="\'.($name).\'"]\');'."\n".
								t(4).'$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());'."\n".
							t(3).'}'."\n".
						t(2).'}'."\n".
						t(2).'$this->_generic->forward("'.$controller.'","ManageAdmin");'."\n";
				      
			$source = substr($source,0,strpos($source,"action()")+8)."\n".
							  t(1).'{'."\n".
							  $action.
							  t(1).'}'."\n".
							  '}'."\n".
							  '?>';
			file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/ManageAdminDelete.controller.php",$source);
						
			$sourceXsl = 	'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
							'<xsl:template name="ManageAdminDelete">'."\n".
							t(1).'<xsl:call-template name="BoMenu" />'."\n".
							t(1).''."\n".
							'</xsl:template>'."\n".
							'</xsl:stylesheet>';
			file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/ManageAdminDelete.xsl",$sourceXsl);
			// ManageAdminDelete
			
			$this->_generic->goDirectTo("SLS_Bo","Bo");
		}
		*/
		$xml->addFullTag("url_add_controller",$this->_generic->getFullPath("SLS_Bo","AddController",array(0=>array("key"=>"isBo","value"=>"true"))),true);
		$this->saveXML($xml);
	}
}
?>